#!/usr/bin/python2.7
#coding=utf-8

__author__ = 'Huang Yuan Yuan'

from rest_framework.throttling import SimpleRateThrottle

class IpThrottle(SimpleRateThrottle):
    # 必须定义
    scope = 'Luffy'
    #     必须重写
    def get_cache_key(self, request, view):
        # 传入request对象，用于获取访问用户ID,作为key
        return self.get_ident(request)

class UserThrottle(SimpleRateThrottle):
    # 必须定义
    scope = 'LuffyUser'
    #     必须重写
    def get_cache_key(self, request, view):
        # 传入request对象，用于获取访问的登录用户名，作为KEY
        return request.user.username